import requests
import json
from config import *


def main():
    url = f"https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={api_key}&client_secret={secret_key}"
    
    payload = ""
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    }
    
    response = requests.post(
        url,
        headers=headers,
        # data=payload,
    )
    
    print(json.dumps(response.json(), indent=4))
    token = response.json()['access_token']
    print('access_token', token)
    
    with open('my_token.py', 'w') as f:
        f.write(f"token = '{token}'\n")


if __name__ == '__main__':
    main()
